import random

from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
from utils.tencent.sms import send_sms_single
from django.conf import settings

def send_sms(request):
    """
    发送短信
    tpl=login=1276452
    tpl=register=1276453
    tpl=reset=1276450

    :param request:
    :return:
    """

    tpl = request.GET.get('tpl')
    template_id = settings.TENCENT_SMS_TEMPLATE.get(tpl)
    if not template_id:
        return HttpResponse('模板不存在')
    code = random.randrange(1000, 9999)
    res = send_sms_single("18842834556", template_id, [code, ])
    if res["result"] == 0:
        return HttpResponse('成功')
    else:
        return HttpResponse(res["errmsg"])
